<?php
/**********************************************************************//**\file
	Armory Page

	Description:  HTML Template abstraction class
*******************************************************************************/

	class armorypage
	{
		protected $pagedata = '';
		protected $pagecontent = '';

		public function __construct($type = null)
		{
			global $constants;

			# Grab global template
			$outer = $this->template($constants['global_template']);
			$this->pagedata = $outer;

			# Grab specialized template (if specified)
			if(!is_null($type))
			{
				$inner = $this->template($constants[$type.'_template']);
				$this->insert('%content%', $inner);
			}
		}

		# Replace a token
		public function insert($token, $replacement)
		{
			$this->pagedata = str_replace($token, $replacement, $this->pagedata);
		}

		# Set the page's title
		public function title($input)
		{
			$this->insert('%title%', $input);
		}

		# Append additional data to the page
		public function add($input)
		{
			$this->pagecontent .= $input;
		}

		public function output()
		{
			$this->insert('%content%', $this->pagecontent);

			echo $this->pagedata;
		}

		# helper functions
		private function template($file)
		{
			return file_get_contents(dirname(__FILE__).'/../'.$file);
		}
	}
?>
